package com.jade.journal.desc;

import java.util.ArrayList;
import java.util.List;

import com.jade.journal.desc.field.Field;
import com.jade.journal.desc.field.Fields;
import org.apache.commons.lang3.StringUtils;

/**
 * 日志的描述类，用于描述各个日志的配置。
 *
 * @author sky
 * @version 1.0 14-9-22 下午12:40
 */
public class JournalDesc
{
    private String name;
    private Fields fields = new Fields();
    private PartitionDesc partition;
    private List<AppenderDesc> appenderDescs;

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Fields getFields()
    {
        return fields;
    }

    public void setFields(Fields fields)
    {
        this.fields = fields;
    }

    public void addField(Field field)
    {
        this.fields.addField(field);
    }

    public PartitionDesc getPartition()
    {
        return partition;
    }

    public void setPartition(PartitionDesc partition)
    {
        this.partition = partition;
    }

    public List<AppenderDesc> getAppenderDescs()
    {
        return appenderDescs;
    }

    public void setAppenderDescs(List<AppenderDesc> appenderDescs)
    {
        this.appenderDescs = appenderDescs;
    }

    public void addAppenderDesc(AppenderDesc desc)
    {
        if (appenderDescs == null) {
            appenderDescs = new ArrayList<AppenderDesc>(1);
        }
        appenderDescs.add(desc);
    }

    public AppenderDesc getAppenderDesc(String type)
    {
        if (appenderDescs == null) {
            return null;
        }
        for (AppenderDesc desc : appenderDescs) {
            if (StringUtils.equalsIgnoreCase(type, desc.getType())) {
                return desc;
            }
        }
        return null;
    }

}
